package course11;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class HashMethod {
    public static void main(String[] args) {
        Map <String,String> hashmap3=new HashMap<>();
        hashmap3.put("name1","张三");
        hashmap3.put("name2","李四");
        hashmap3.put("name3","王五");
        System.out.println("hashmap3的元素个数"+hashmap3.size());
        //遍历方法1
        /*Iterator iter=hashmap3.entrySet().iterator();
        while (iter.hasNext()){
            Map.Entry name=(Map.Entry)iter.next();
            String namekey=(String)name.getKey();
            String namevalue=(String)name.getValue();
            System.out.println(namekey+"'s name is"+namevalue);*/
            //遍历方法2java8新增 foreach
            hashmap3.forEach((key,value)->{
                System.out.println("[key="+key+",value="+value+"]");
                });
        }
    }
